import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import java.util.List;

public class Bat {
    private int x;
    int health = 2;
    boolean active = true;
    private int animationCounter = 0;
    private int currentFrame = 0;

    private List<Image> batFrames;
    private static final int ANIMATION_SPEED = 8;

    public Bat(int x, List<Image> batFrames) {
        this.x = x;
        this.batFrames = batFrames;
    }

    public void update(int speed) {
        x -= speed;
        animationCounter++;
        if (animationCounter >= ANIMATION_SPEED) {
            animationCounter = 0;
            currentFrame = (currentFrame + 1) % batFrames.size();
        }
    }

    public void render(GraphicsContext gc, int screenHeight, int gridSize) {
        if (active) {
            double batY = screenHeight - gridSize * 2.5;
            gc.drawImage(batFrames.get(currentFrame), x, batY, gridSize, gridSize);
        }
    }

    public boolean checkCollision(int playerX, int playerY, int width, int height,
                                  boolean isPlayerSliding, int gridSize) {
        if (active) {
            return !isPlayerSliding &&
                    playerX + width > x + gridSize*0.2 &&
                    playerX < x + gridSize*0.8;
        }
        return false;
    }

    public boolean checkBombCollision(Bomb bomb, int gridSize) {
        if (active) {
            double batY = GameConstants.getScreenHeight() - gridSize * 1.75;
            return bomb.x + bomb.width > x &&
                    bomb.x < x + gridSize &&
                    bomb.y + bomb.height > batY &&
                    bomb.y < batY + gridSize;
        }
        return false;
    }

    public boolean isActive() {
        return active;
    }

    public int getX() {
        return x;
    }
}